package com.sino.tb.confirm.entiry;


import java.util.*;
import java.sql.*;
import com.sino.tb.Power.*;
import xpubbean.Db.*;


public class ConfirmPower {
    private double freeValue1025;
    private double freeValue1026;
    private double freeValue1070;
    private double perMaxAmount1025;
    private double perMaxAmount1026;
    private double perMaxAmount1070;
    private double perMinAmount1025;
    private double perMinAmount1026;
    private double perMinAmount1070;
    private double sumValue1025;
    private double sumValue1026;
    private double sumValue1070;
    private double yearMaxAmount1025;
    private double yearMaxAmount1026;
    private double yearMaxAmount1070;
    private String protOrg;
    private String protLevel;
    private String protPercent;

    public ConfirmPower(LoginInfo loginInfo, Connection conn) {
        String sql = "SELECT t1.*, nvl(t2.c_sum_value, 0) c_sum_value,  t1.c_year_max_amount - nvl(t2.c_sum_value, 0) c_free_value " +
            "FROM ( SELECT * FROM   v_pub_confirm_power WHERE  c_org_id = " +
            loginInfo.getOrgID() + ") t1, " +
            "(select c_prj_seq,c_org_audit, c_sum c_sum_value from v_pub_confirm_stat WHERE  c_org_audit = " +
            loginInfo.getOrgID() + " order by c_prj_seq ) t2 " +
            "where t1.c_org_id = t2.c_org_audit(+) and t1.c_confirm_type = t2.c_prj_seq(+) ";

        ResultSetPlus rs = new ResultSetPlus(sql, conn);
        while (rs.next()) {
            switch (Integer.parseInt(rs.getFieldStr("c_confirm_type"))) {
            case 1025:
                this.setPerMaxAmount1025(Double.parseDouble(rs.getFieldStr(
                    "c_per_max_amount")));
                this.setPerMinAmount1025(Double.parseDouble(rs.getFieldStr(
                    "c_per_min_amount")));
                this.setYearMaxAmount1025(Double.parseDouble(rs.getFieldStr(
                    "c_year_max_amount")));
                this.setSumValue1025(Double.parseDouble(rs.getFieldStr(
                    "c_sum_value")));
                this.setFreeValue1025(Double.parseDouble(rs.getFieldStr(
                    "c_free_value")));
                break;
            case 1026:
                this.setPerMaxAmount1026(Double.parseDouble(rs.getFieldStr(
                    "c_per_max_amount")));
                this.setPerMinAmount1026(Double.parseDouble(rs.getFieldStr(
                    "c_per_min_amount")));
                this.setYearMaxAmount1026(Double.parseDouble(rs.getFieldStr(
                    "c_year_max_amount")));
                this.setSumValue1026(Double.parseDouble(rs.getFieldStr(
                    "c_sum_value")));
                this.setFreeValue1026(Double.parseDouble(rs.getFieldStr(
                    "c_free_value")));
                break;
            case 1070:
                this.setPerMaxAmount1070(Double.parseDouble(rs.getFieldStr(
                    "c_per_max_amount")));
                this.setPerMinAmount1070(Double.parseDouble(rs.getFieldStr(
                    "c_per_min_amount")));
                this.setYearMaxAmount1070(Double.parseDouble(rs.getFieldStr(
                    "c_year_max_amount")));
                this.setSumValue1070(Double.parseDouble(rs.getFieldStr(
                    "c_sum_value")));
                this.setFreeValue1070(Double.parseDouble(rs.getFieldStr(
                    "c_free_value")));
                break;
            }
        }
    }


    public ConfirmPower(LoginInfo loginInfo, String type, Connection conn) {
        String sql = "SELECT t1.*, nvl(t2.c_sum_value, 0) c_sum_value,  t1.c_year_max_amount - nvl(t2.c_sum_value, 0) c_free_value " +
            "FROM ( SELECT * FROM   v_pub_confirm_power WHERE  c_org_id = " +
            loginInfo.getOrgID() + ") t1, " +
            "(select c_prj_seq,c_org_audit, c_sum c_sum_value from v_pub_confirm_stat WHERE  c_org_audit = " +
            loginInfo.getOrgID() + " order by c_prj_seq ) t2 " +
            "where t1.c_org_id = t2.c_org_audit(+) and t1.c_confirm_type = t2.c_prj_seq(+) and t1.c_type = " +
            type + " ";

        ResultSetPlus rs = new ResultSetPlus(sql, conn);
        while (rs.next()) {
            switch (Integer.parseInt(rs.getFieldStr("c_confirm_type"))) {
            case 1025:
                this.setPerMaxAmount1025(Double.parseDouble(rs.getFieldStr(
                    "c_per_max_amount")));
                this.setPerMinAmount1025(Double.parseDouble(rs.getFieldStr(
                    "c_per_min_amount")));
                this.setYearMaxAmount1025(Double.parseDouble(rs.getFieldStr(
                    "c_year_max_amount")));
                this.setSumValue1025(Double.parseDouble(rs.getFieldStr(
                    "c_sum_value")));
                this.setFreeValue1025(Double.parseDouble(rs.getFieldStr(
                    "c_free_value")));
                break;
            case 1026:
                this.setPerMaxAmount1026(Double.parseDouble(rs.getFieldStr(
                    "c_per_max_amount")));
                this.setPerMinAmount1026(Double.parseDouble(rs.getFieldStr(
                    "c_per_min_amount")));
                this.setYearMaxAmount1026(Double.parseDouble(rs.getFieldStr(
                    "c_year_max_amount")));
                this.setSumValue1026(Double.parseDouble(rs.getFieldStr(
                    "c_sum_value")));
                this.setFreeValue1026(Double.parseDouble(rs.getFieldStr(
                    "c_free_value")));
                break;
            case 1070:
                this.setPerMaxAmount1070(Double.parseDouble(rs.getFieldStr(
                    "c_per_max_amount")));
                this.setPerMinAmount1070(Double.parseDouble(rs.getFieldStr(
                    "c_per_min_amount")));
                this.setYearMaxAmount1070(Double.parseDouble(rs.getFieldStr(
                    "c_year_max_amount")));
                this.setSumValue1070(Double.parseDouble(rs.getFieldStr(
                    "c_sum_value")));
                this.setFreeValue1070(Double.parseDouble(rs.getFieldStr(
                    "c_free_value")));
                break;
            }
        }
        sql = "select * from t_pub_confirm_power_per where c_user_id  = " +
            loginInfo.getUserID() + " and c_confirm_type = 0";
        rs = new ResultSetPlus(sql, conn);
        if (rs.next()) {
            this.setPerMaxAmount1026(Double.parseDouble(rs.getFieldStr(
                "c_per_max_amount")));
            this.setPerMinAmount1026(Double.parseDouble(rs.getFieldStr(
                "c_per_min_amount")));
            this.setYearMaxAmount1026(Double.parseDouble(rs.getFieldStr(
                "c_year_max_amount")));
        }
    }


    public ConfirmPower(LoginInfo loginInfo, int type, Connection conn) {
        String sql = "";
        switch (type) {
        case 1:
            sql = " select * from v_pub_prot_power where c_org_id = " +
                loginInfo.getOrgID();
            ResultSetPlus rsp = new ResultSetPlus(sql, conn);
            if (rsp.next()) {
                this.setProtLevel(rsp.getFieldStr("c_org_level"));
                this.setProtOrg(rsp.getFieldStr("c_org_id"));
                this.setProtPercent(rsp.getFieldStr("c_percent"));
            }
            break;

        }
    }


    public double getFreeValue1025() {
        return freeValue1025;
    }


    public void setFreeValue1025(double freeValue1025) {
        this.freeValue1025 = freeValue1025;
    }


    public double getFreeValue1026() {
        return freeValue1026;
    }


    public void setFreeValue1026(double freeValue1026) {
        this.freeValue1026 = freeValue1026;
    }


    public double getFreeValue1070() {
        return freeValue1070;
    }


    public void setFreeValue1070(double freeValue1070) {
        this.freeValue1070 = freeValue1070;
    }


    public double getPerMaxAmount1025() {
        return perMaxAmount1025;
    }


    public void setPerMaxAmount1025(double perMaxAmount1025) {
        this.perMaxAmount1025 = perMaxAmount1025;
    }


    public double getPerMaxAmount1026() {
        return perMaxAmount1026;
    }


    public void setPerMaxAmount1026(double perMaxAmount1026) {
        this.perMaxAmount1026 = perMaxAmount1026;
    }


    public double getPerMaxAmount1070() {
        return perMaxAmount1070;
    }


    public void setPerMaxAmount1070(double perMaxAmount1070) {
        this.perMaxAmount1070 = perMaxAmount1070;
    }


    public double getPerMinAmount1025() {
        return perMinAmount1025;
    }


    public void setPerMinAmount1025(double perMinAmount1025) {
        this.perMinAmount1025 = perMinAmount1025;
    }


    public double getPerMinAmount1026() {
        return perMinAmount1026;
    }


    public void setPerMinAmount1026(double perMinAmount1026) {
        this.perMinAmount1026 = perMinAmount1026;
    }


    public double getPerMinAmount1070() {
        return perMinAmount1070;
    }


    public void setPerMinAmount1070(double perMinAmount1070) {
        this.perMinAmount1070 = perMinAmount1070;
    }


    public double getSumValue1025() {
        return sumValue1025;
    }


    public void setSumValue1025(double sumValue1025) {
        this.sumValue1025 = sumValue1025;
    }


    public double getSumValue1026() {
        return sumValue1026;
    }


    public void setSumValue1026(double sumValue1026) {
        this.sumValue1026 = sumValue1026;
    }


    public double getSumValue1070() {
        return sumValue1070;
    }


    public void setSumValue1070(double sumValue1070) {
        this.sumValue1070 = sumValue1070;
    }


    public double getYearMaxAmount1025() {
        return yearMaxAmount1025;
    }


    public void setYearMaxAmount1025(double yearMaxAmount1025) {
        this.yearMaxAmount1025 = yearMaxAmount1025;
    }


    public double getYearMaxAmount1026() {
        return yearMaxAmount1026;
    }


    public void setYearMaxAmount1026(double yearMaxAmount1026) {
        this.yearMaxAmount1026 = yearMaxAmount1026;
    }


    public double getYearMaxAmount1070() {
        return yearMaxAmount1070;
    }


    public void setYearMaxAmount1070(double yearMaxAmount1070) {
        this.yearMaxAmount1070 = yearMaxAmount1070;
    }


    public String getProtOrg() {
        return protOrg;
    }


    public void setProtOrg(String protOrg) {
        this.protOrg = protOrg;
    }


    public String getProtLevel() {
        return protLevel;
    }


    public void setProtLevel(String protLevel) {
        this.protLevel = protLevel;
    }


    public String getProtPercent() {
        return protPercent;
    }


    public void setProtPercent(String protPercent) {
        this.protPercent = protPercent;
    }
}
